package com.example.service.impl;

import com.example.dao.CashDao;
import com.example.domain.pojo.Cash;
import com.example.domain.result.PageResult;
import com.example.service.CashService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class CashServiceImpl implements CashService {

    @Autowired
    private CashDao cashDao;

    //查询已经提现记录
    @Override
    public PageResult findPage(String queryString, Integer currentPage, Integer pageSize) {

        Integer status=1;
        //使用插件
        PageHelper.startPage(currentPage,pageSize);
        //查询
        List<Cash> pageList = cashDao.findCashRecord(status);
        //封装数据
        PageInfo<Cash> info=new PageInfo<>(pageList);
        //返回查询的结果集
        return new PageResult(info.getTotal(),info.getList());

    }

    //未提现的
    @Override
    public PageResult findPageCashRecord(String queryString, Integer currentPage, Integer pageSize) {
        Integer status=0;
        //使用插件
        PageHelper.startPage(currentPage,pageSize);
        //查询
        List<Cash> pageList = cashDao.findCashRecord(status);
        //封装数据
        PageInfo<Cash> info=new PageInfo<>(pageList);
        //返回查询的结果集
        return new PageResult(info.getTotal(),info.getList());
    }

    /**
     * 确认提现
     * @param id
     * @return
     */
    @Override
    public Boolean updateCashStatus(Long id) {

        try {
            Map map=new HashMap();
            map.put("date",new Date());
            map.put("id",id);
            cashDao.updateOrderStatus(map);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;

    }
}
